"use strict";
// TODO 封装成一个npm包
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoomState = exports.Player = exports.LiftDetails = exports.ROUND_STATE = void 0;
/** 房间状态 */
var ROUND_STATE;
(function (ROUND_STATE) {
    /** 空闲的 */
    ROUND_STATE["IDLE"] = "IDLE";
    //   新加的
    ROUND_STATE["PLAYING"] = "PLAYING";
    /** 发牌中 */
    ROUND_STATE["DEALING"] = "DEALING";
    /** 轮次开始 */
    ROUND_STATE["TURNS"] = "TURNS";
    /** 结束 */
    ROUND_STATE["END"] = "END";
})(ROUND_STATE = exports.ROUND_STATE || (exports.ROUND_STATE = {}));
// /** 用户状态 */
// export enum USER_STATE {
//     /** 空闲的 */
//     IDLE = "IDLE",
//     /** 等待中 */ // 正常出牌
//     WAITING_PLAY = "WAITING_PLAY",
//     /** 等待中 */ // 需要选牌
//     WAITING_SELECT = "WAITING_SELECT",
//     /** 出牌 */
//     PLAY = "PLAY",
//     /** 掀牌 */
//     LIFT = "LIFT",
//     /** 过 */
//     PASS = "PASS",
// }
const schema_1 = require("@colyseus/schema");
const enum_1 = require("../typing/enum");
class LiftDetails extends schema_1.Schema {
    constructor() {
        super(...arguments);
        this.fromId = '';
        this.toId = '';
        this.isCorrect = false;
        // 上一手牌 参与的人都能看到
        this.lastPlayedCards = new schema_1.ArraySchema();
        // 桌上发的牌 只有掀错或者被掀对人都能看到
        this.deskCards = new schema_1.ArraySchema();
        this.lastPlayedCardsCount = 0;
        this.deskCardsCount = 0;
    }
}
__decorate([
    (0, schema_1.type)("string")
], LiftDetails.prototype, "fromId", void 0);
__decorate([
    (0, schema_1.type)("string")
], LiftDetails.prototype, "toId", void 0);
__decorate([
    (0, schema_1.type)("boolean")
], LiftDetails.prototype, "isCorrect", void 0);
__decorate([
    (0, schema_1.filter)(function (client) {
        return this.fromId === client.sessionId || this.toId === client.sessionId;
    }),
    (0, schema_1.type)(["number"])
], LiftDetails.prototype, "lastPlayedCards", void 0);
__decorate([
    (0, schema_1.filter)(function (// the instance of the class `@filter` has been defined (instance of `Card`)
    client) {
        const isCome = this.fromId === client.sessionId;
        const isGo = this.toId === client.sessionId;
        if (isCome || isGo) {
            return this.isCorrect ? isGo : isCome;
        }
        return false;
    }),
    (0, schema_1.type)(["number"])
], LiftDetails.prototype, "deskCards", void 0);
__decorate([
    (0, schema_1.type)("number")
], LiftDetails.prototype, "lastPlayedCardsCount", void 0);
__decorate([
    (0, schema_1.type)("number")
], LiftDetails.prototype, "deskCardsCount", void 0);
exports.LiftDetails = LiftDetails;
class Player extends schema_1.Schema {
    constructor(sessionId, id) {
        super();
        /** 用户昵称 */
        this.nick = '';
        // 剩余手牌
        this.leftCards = new schema_1.ArraySchema();
        /** 剩余牌的数量 */
        this.leftCount = 0;
        /** 打出的牌的数量 */
        this.playCardsCount = 0;
        /** 玩家状态 */
        this.status = enum_1.USER_STATUS.IDLE;
        /** 操作状态 */
        this.opStatus = enum_1.OP_STATUS.UNDO;
        /** 是否是自己 */
        this.self = true;
        /** 是否胜利 */
        this.isWin = false;
        // 是否连接
        this.connected = true;
        this.sessionId = sessionId;
        this.roundId = id;
    }
}
__decorate([
    (0, schema_1.type)("number")
], Player.prototype, "level", void 0);
__decorate([
    (0, schema_1.type)("string")
], Player.prototype, "nick", void 0);
__decorate([
    (0, schema_1.type)("string")
], Player.prototype, "avatar", void 0);
__decorate([
    (0, schema_1.type)("string")
], Player.prototype, "sessionId", void 0);
__decorate([
    (0, schema_1.filterChildren)(function (client) {
        return client.sessionId === this.sessionId;
    }),
    (0, schema_1.type)(["number"])
], Player.prototype, "leftCards", void 0);
__decorate([
    (0, schema_1.type)("number")
], Player.prototype, "leftCount", void 0);
__decorate([
    (0, schema_1.type)("number")
], Player.prototype, "playCardsCount", void 0);
__decorate([
    (0, schema_1.type)("string")
], Player.prototype, "status", void 0);
__decorate([
    (0, schema_1.type)("string")
], Player.prototype, "opStatus", void 0);
__decorate([
    (0, schema_1.filter)(function (client) {
        return this.sessionId === client.sessionId;
    }),
    (0, schema_1.type)("boolean")
], Player.prototype, "self", void 0);
__decorate([
    (0, schema_1.type)("number")
], Player.prototype, "roundId", void 0);
__decorate([
    (0, schema_1.type)("boolean")
], Player.prototype, "isWin", void 0);
exports.Player = Player;
class RoomState extends schema_1.Schema {
    constructor() {
        super(...arguments);
        /** 所有玩家 */
        this.players = new schema_1.MapSchema();
        /** 房间状态 */
        this.roundState = ROUND_STATE.IDLE;
        /** 下一轮次时间 */
        this.startTime = 0;
        /** 服务端当前时间 */
        this.currentTime = 0;
        /** 当前已打出的牌的数量 */
        this.playedCardsNum = 0;
        /** 掀牌相关信息 */
        this.liftDetails = new LiftDetails();
    }
}
__decorate([
    (0, schema_1.type)({ map: Player })
], RoomState.prototype, "players", void 0);
__decorate([
    (0, schema_1.type)("string")
], RoomState.prototype, "roundState", void 0);
__decorate([
    (0, schema_1.type)("number")
], RoomState.prototype, "currentGuessCard", void 0);
__decorate([
    (0, schema_1.type)("number")
], RoomState.prototype, "startTime", void 0);
__decorate([
    (0, schema_1.type)("number")
], RoomState.prototype, "currentTime", void 0);
__decorate([
    (0, schema_1.type)("number")
], RoomState.prototype, "playedCardsNum", void 0);
__decorate([
    (0, schema_1.type)(LiftDetails)
], RoomState.prototype, "liftDetails", void 0);
exports.RoomState = RoomState;
